package d6_byte_stream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 2024/6/14 Cjj 掌握FileInputStreamTest 每次读取多个字节 7:25
 */
public class FileInputStreamTest2 {
    public static void main(String[] args) throws IOException {
        //1.创建一个字节输入流对象代表字节输入流管道与源文件接通
        InputStream in = new FileInputStream("file-io\\src\\main\\test\\abab.txt");

        //2.读取源文件中字节数据,每次读取多个字节
        //
        /*byte[] bytes= new byte[2];
        int read = in.read(bytes);
        String s = new String(bytes);
        System.out.println(s);
        System.out.println("当次读取的字节数：" + read);

        int read1 = in.read(bytes);
        //读取多少 倒出多少
        String s1 = new String(bytes,0,read1);
        System.out.println(s1);
        System.out.println("当次读取的字节数："+read1);

        int read2 = in.read(bytes);
        String s2 = new String(bytes);
        System.out.println(read2);
        System.out.println("当次读取的字节数："+s2);*/

        byte[] bytes = new byte[3];
        int len;//每次读取了多个字节
        while ((len=in.read(bytes))!=-1){
            String s = new String(bytes, 0, len);
            System.out.print(s);
        }
            in.close();
    }
}
